package structures;

import javax.swing.table.AbstractTableModel;


public class MyTableModel extends AbstractTableModel 
{
	private static final long serialVersionUID = 1L;
	private Object[][] data;
	private String[] columnNames;
	
	public MyTableModel(Object[][] newData, String[] colNames)
	{
		data = newData;
		columnNames = colNames;
	}
	
	@Override
	public int getRowCount() 
	{
		return data.length;
	}

	@Override
	public int getColumnCount() 
	{
		return columnNames.length;
	}

	@Override
	public Object getValueAt(int row, int col) 
	{
		return data[row][col];
	}
	
	public Class getColumnClass(int c)
	{
		return getValueAt(0,c).getClass();
	}
	
	public void setValueAt(Object value, int row, int col)
	{
		data[row][col] = value;
		fireTableCellUpdated(row,col);
	}
	 public boolean isCellEditable(int row, int col) {
         //Note that the data/cell address is constant,
         //no matter where the cell appears onscreen.
         if (col < 0) {
             return false;
         } else {
             return true;
         }
     }
	 
	 public String getColumnName(int col)
	 {
		 return columnNames[col];
	 }

}
